#! /usr/bin/env python
# -*- coding: utf-8 -*-

device_type = '储罐'
device_type_key = 'cg'
index_type = '温度'
index_type_key = 'cgwd'
device_name = '液氨'
alarm_start_time = '2025-06-04 00:00:00'
alarm_end_time = '2025-06-05 00:00:00'
alarm_type = '低报'
alarm_type_key = 3
alarm_status = '已消警'
alarm_status_key = 'extinguished_alarm'
fire_start_time = '2025-06-04 00:00:00'
fire_end_time = '2025-06-05 00:00:00'
danger_type = '罐区'  # 0
danger_type_key = 0
danger_level = '二级'  # 2
danger_level_key = 2
danger_name = '测试重大危险源-xmj'
danger_id = '测试重大危险源-xmj'
company_name = '福建优力特材料有限公司'
company_id = '1820379858379681793'

query_sql = '''
select count(*) from (
SELECT
	mmai.id
FROM
	hgyq_major_hazard_sources.mw_m_alarm_info mmai
WHERE
	mmai.is_deleted = 0 
	AND mmai.alarm_obj_type = "''' + device_type_key + '''" 
	AND mmai.alarm_index_type = "''' + index_type_key + '''" 
	AND mmai.object_name like "%''' + device_name + '''%"
	AND mmai.alarm_time BETWEEN "''' + alarm_start_time + '''" AND "''' + alarm_end_time + '''"
	AND mmai.alarm_type = ''' + str(alarm_type_key) + '''
	AND mmai.alarm_status = "''' + alarm_status_key + '''"
	AND mmai.fire_time BETWEEN "''' + fire_start_time + '''" AND "''' + fire_end_time + '''"
	AND mmai.create_dept = ''' + company_id + '''
	
	AND mmai.major_hazard_id IN ( SELECT id FROM hgyq_synthetical.ha_m_great_risk_bill 
	WHERE type = ''' + str(danger_type_key) + ''' AND LEVEL = ''' + str(
    danger_level_key) + ''' AND NAME LIKE "%''' + danger_name + '''%"
	 )
) t
'''

reset_sql = '''
SELECT
	count(*)
FROM
	hgyq_major_hazard_sources.mw_m_alarm_info mmai
WHERE
	mmai.is_deleted = 0 
	AND mmai.create_dept = ''' + company_id + '''
'''
